package org.jeecg.modules.demo.drfReviewAssignments.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.demo.drfReviewAssignments.entity.DrfReviewAssignments;
import org.jeecg.modules.demo.drfpapers.entity.DrfPapers;

import java.util.List;

/**
 * @Description: 审核任务表
 * @Author: jeecg-boot
 * @Date:   2025-10-02
 * @Version: V1.0
 */
@Mapper
public interface DrfReviewAssignmentsMapper extends BaseMapper<DrfReviewAssignments> {

    /**
     * 获取需要确认评审的论文数
     * @param id
     * @return
     */
    //根据教师id获取需要确认评审的论文数
    @Select("select count(*) from drf_review_assignments where status = 'sent' and (teacher_id = #{id})")
    Integer getNeedReviewCount(String id);
    /**
     * 获取待提交意见的论文数
     * @param id
     * @return
     */
    @Select("select count(*) from drf_review_assignments where status = 'reviewing' and (teacher_id = #{id})")
    Integer getWaitingForReviewCount(String id);

    /**
     * 获取需要确认评审的论文id
     * @param id
     * @return
     */
    @Select("select paper_id from drf_review_assignments where status = 'sent' and (teacher_id = #{id})")
    List<String> getNeedReviewPapers(String id);


    /**
     * 修改审核任务表中的论文状态
     *
     * @param id
     * @param status
     * @return
     */
    @Update("update drf_review_assignments set status = #{status} where paper_id = #{id} AND teacher_id = #{userId}")
    int updatePaperStatus(String id, String status, String userId);

    /**
     * 获取待提交意见的论文列表
     * @param userId
     * @return
     */
    @Select("select * from drf_papers where id in (select paper_id from drf_review_assignments where status = 'reviewing' and teacher_id = #{userId})")
    List<DrfPapers> getWaitingForReviewPapers(String userId);

    /**
     * 根据教师id获取审核任务表信息
     * @param userId
     * @return
     */
    @Select("select * from drf_review_assignments where teacher_id = #{userId}")
    DrfReviewAssignments getByTeacherId(String userId);

    /**
     * 修改审核任务表状态
     * @param id
     * @param
     * @return
     */
    @Select("update drf_review_assignments set status = #{status} where paper_id = #{id} AND teacher_id = #{userId}")
    int updateStatus(String id, String userId ,String status);

    /**
     * 根据论文id获取审核任务表数量，且需要状态为审核结束
     * @param id
     * @return
     */
    @Select("select count(*) from drf_review_assignments where paper_id = #{id} and status = 'reviewEnd'")
    int getCountByPaperId(String id);

    /**
     * 根据论文id获取审核任务表数量，且需要状态为审核中
     * @param paperId
     * @return
     */
    @Select("select count(*) from drf_review_assignments where paper_id = #{paperId} and status = 'reviewing'")
    int getStatusCount(String paperId);

    /**
     * 获取状态为reject的论文id
     * @return
     */
    @Select("select paper_id from drf_review_assignments where status = 'reject'")
    List<String> getNotAcceptPaper();

    //根据论文id获取审核任务表信息
    @Select("select * from drf_review_assignments where paper_id = #{id}")
    List<DrfReviewAssignments> getByPaperId(String id);
}
